﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Caliburn.Micro;
using Microsoft.Phone.Controls;

namespace Phone.Framework.CaliburnExtensions.Results
{
    public class SwitchButtonIconResult : IResult
    {

        public void Execute(ActionExecutionContext context)
        {
            //var page = context.Target as PhoneApplicationPage;
            //page.ApplicationBar
            //var text = context.Message.ButtonSource.Text;
        }

        public event EventHandler<ResultCompletionEventArgs> Completed;
    }


    public class AppButtonResult : IResult
    {
        private bool? _isEnabled;
        public AppButtonResult()
        {
        }

        public AppButtonResult(bool isEnabled)
        {
            _isEnabled = isEnabled;
        }

        public void Execute(ActionExecutionContext context)
        {
            if (_isEnabled.HasValue)
            {
                context.Message.ButtonSource.IsEnabled = _isEnabled.Value;
            }
            else
            {
                var isEnabled = context.Message.ButtonSource.IsEnabled;
                context.Message.ButtonSource.IsEnabled = !isEnabled;
            }
            Completed(this, new ResultCompletionEventArgs());
        }

        public event EventHandler<ResultCompletionEventArgs> Completed;
    }

    public class AppMenuItemResult : IResult
    {
        public void Execute(ActionExecutionContext context)
        {
            var isEnabled = context.Message.MenuItemSource.IsEnabled;
            context.Message.MenuItemSource.IsEnabled = !isEnabled;
            Completed(this, new ResultCompletionEventArgs());
        }

        public event EventHandler<ResultCompletionEventArgs> Completed;
    }
}